from flask import Blueprint, request
from models.borrow_record import BorrowRecord

borrow_blueprint = Blueprint('borrow_bp', __name__, url_prefix='/')


@borrow_blueprint.route('/records', methods=['GET'])
def get_records():
    return BorrowRecord.get_records()


@borrow_blueprint.route('/records', methods=['POST'])
def add_record():
    data = request.get_json()
    book_id = data.get('bookId')
    person_id = data.get('personId')
    return BorrowRecord.add_record(book_id, person_id)


@borrow_blueprint.route('/records/<recordId>', methods=['PUT'])
def update_record(recordId):
    return BorrowRecord.update_record(recordId)


@borrow_blueprint.route('/records/<recordId>', methods=['DELETE'])
def delete_record(recordId):
    return BorrowRecord.delete_record(recordId)